package com.itheima.article.controller;

import com.itheima.article.pojo.ApAuthor;
import com.itheima.article.service.ApAuthorService;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApiController {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 查询作者账号
     *
     * @param apUserId
     * @param wmUserId
     * @return
     */
    @GetMapping("/api/ApAuthor/getByApUserId/{apUserId}/{wmUserId}")
    public ResultVo<ApAuthor> getByApUserAndWmUserId(@PathVariable(value = "apUserId") Long apUserId,
                                                     @PathVariable(value = "wmUserId") Long wmUserId) {
        ApAuthor author = apAuthorService.getByApUserAndWmUserId(apUserId, wmUserId);
        return ResultVo.ok(author);
    }

    /**
     * 查询作者账号
     *
     * @param apAuthor
     * @return
     */
    @PostMapping("/api/ApAuthor/add")
    public ResultVo addApAuthor(@RequestBody ApAuthor apAuthor) {
        apAuthorService.save(apAuthor);
        return ResultVo.ok();
    }
}
